package com.health.fragment.focusgroup;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.health.tablebean.BD_DD_DRUG;
import com.health.tablebean.CD_DIABETESFOLLOWUP;
import com.health.tablebean.JTYSCustomerDoctorCont;
import com.health.tablebean.JTYS_SignPictureData;
import com.health.tablebean.SBCL_DATA;
import com.health.tools.ImageTools;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentUpData;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.GXYActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.ARCHIVE_GENERALCONDITION;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.viewscontrols.focusgroup.TNBActivity;
import com.health.viewscontrols.medical.adapter.MedicalAdapter;
import com.health.viewscontrols.medical.adapter.SfDrugAdapter;
import com.health.viewscontrols.medical.bean.SfHistoryBean;
import com.health.viewscontrols.qyinfo.QYInfo;
import com.health.viewscontrols.qyinfo.QianMingActivity;
import com.health.viewscontrols.settings.QueryDrugListActivity;
import com.health.viewscontrols.tjbg.CameraActivity;
import com.health.viewscontrols.tupian.ClipActivity1;
import com.health.widget.EditTextWithDate2;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.RequiresApi;
import android.support.v4.content.FileProvider;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONObject;

/**
 * 重点人群-- 高血压--随访
 *
 * @author nova
 *
 */
public class GXY_SfFragment extends NovaFragment implements onFragmentSave, onFragmentUpData, OnClickListener {
	private static final String TAG = "GXY_SfFragment";
	private View cqsf2View = null;
	private FDbManager fdbmanger = null;

	// ------------------------------基本信息-----------------------------
	private EditTextWithDate2 ed_date;
	private NiceSpinner ed_sfys;// 随访医生
	private NiceSpinner nice_spinner_szfs;// 选择随诊方式

	private MyGridView gd_zz;// 症状

	private EditText ed_xy;// 血压
	private Button btn_choose_xy;

	private EditText ed_xl;// 心率
	private EditText ed_tz;// 体重
	private Button btn_choose_tz;// 选择体重
	private EditText ed_xcsfmb_tz;// 下次随访目标 体重
	private Button btn_choose_xl;


	private EditText ed_tzzs;// 体质指数
	private EditText ed_height;// 身高
	private EditText ed_tzzs_sf;// 体质指数 随访
	private EditText ed_qt;// 其他
	private EditText ed_rxyl;// 日吸烟量
	private EditText ed_xcsfmb_xy;// 日吸烟量 随访
	private EditText ed_ryjl;// 日饮酒量

	private EditText ed_xcsfmb_yj;// 日饮酒量 随访
	private EditText ed_yd_zq;// 运动周
	private EditText ed_yd_min;// 运动分钟
	private EditText ed_xcsfmb_yd_zq;// 运动周
	private EditText ed_xcsfmb_yd_min;// 运动分钟
	private NiceSpinner nice_spinner_syqk;// 摄盐情况
	private EditText syqk_edt;//每日摄盐情况
	private NiceSpinner nice_spinner_xcsfmb;// 摄盐情况
	private NiceSpinner nice_spinner_xltz;// 摄盐情况
	private NiceSpinner nice_spinner_zyxw;// 遵医行为

	private EditText ed_fzjc;// 辅助检查
	private NiceSpinner nice_spinner_fyycx;// 服药依从性
	private MyGridView gd_ywblfy;// 药物不良反应

	private NiceSpinner nice_spinner_clsffl;// 此类随访分类
//	private AutoCompleteTextView ed_ywmc1;// 药物名称1
//	private EditText nice_spinner_dw1;// 药物单位1
//	private EditText nice_spinner_dw2;// 药物单位2
//	private EditText nice_spinner_dw3;// 药物单位3
//	private EditText nice_spinner_dwqt;// 药物单位其他
//	private EditText ed_ywmc1_day;// 每日 day
//	private EditText ed_ywmc1_mg;// 每次 mg
//	private AutoCompleteTextView ed_ywmc2;// 药物名称2
//	private EditText ed_ywmc2_day;// 每日 day
//	private EditText ed_ywmc2_mg;// 每次 mg
//	private AutoCompleteTextView ed_ywmc3;// 药物名称3
//	private EditText ed_ywmc3_day;// 每日 day
//	private EditText ed_ywmc3_mg;// 每次 mg
//	private AutoCompleteTextView ed_qtyw;// 药物名称3
//	private EditText ed_qtyw_day;// 每日 day
//	private EditText ed_qtyw_mg;// 每次 mg

	private EditText ed_zzyy;// 转诊原因
	private EditText ed_jgkb;// 机构及科别
	private EditTextWithDate2 ed_xcsfsj;// 下次随访时间

	private RadioGroup zhuanzhen_group;//是否转诊
	private RadioButton zhuanzhen_no;
	private RadioButton zhuanzhen_yes;
	private LinearLayout zhuanzhen_layout;
	String isREFERRAL="DM01-11_1";//是否转诊
	EditText jiankangjianyi;//健康评价

	// ----------------------------------------------------------------------
	private RadioButtonAdapter adapter_ywblfy = null;

	private CheckBoxAdapter adapter_zz = null;

	private List<BD_DD_INFO> sy_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> xcsfmb_list = new ArrayList<BD_DD_INFO>();

	private List<BD_DD_INFO> xltz_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> zyxw_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ywycx_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> szfs_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ccsffl_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ywdw_list = new ArrayList<BD_DD_INFO>();
	public ARCHIVE_BASEINFO userInfo;
	private CD_HYPERTENSIONFOLLOWUP followUp;
	String strWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";
	private CD_HYPERTENSIONFOLLOWUP readFollowup;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	// 定义字符串数组，作为提示的文本
	String[] gxy_yws = new String[] { "缬沙坦片", "复方利血平片", "复方利血平氨苯蝶啶片", "硝苯地平缓释片", "硝苯地平控释片", "卡托普利片", "尼莫地平片",
			"马来酸依那普利片", "苯磺酸氨氯地平片", "吲达帕胺片", "依那普利片", "心普利片", "心胺利片", "硝苯地平片", "尼群地平片", };
	List<ARCHIVE_GENERALCONDITION> ags;
	private String gaoya = "0";
	private String diya = "0";
//	private EditText nice_spinner_cc1;
//	private EditText nice_spinner_cc2;
//	private EditText nice_spinner_cc3;
//	private EditText nice_spinner_cc4;
	private List<String> ccList;
	private List<String> ylList;
//	private EditText nice_spinner_yl1;
//	private EditText nice_spinner_yl2;
//	private EditText nice_spinner_yl3;
//	private EditText nice_spinner_yl4;
	private static final int DRUG_NAME1 = 0x0001;
	private static final int DRUG_NAME2 = 0x0002;
	private static final int DRUG_NAME3 = 0x0003;
	private static final int DRUG_NAME4 = 0x0004;
	private static final int DRUG_NAME11 = 0x0005;
	private static final int DRUG_NAME21 = 0x0006;
	private static final int DRUG_NAME31 = 0x0007;
	private static final int DRUG_NAME41 = 0x0008;

	private Button bt_paizhao;
	private ImageView iv_paizhao_img;

//	private TextView tv_drug_del1;
//	private TextView tv_drug_del2;
//	private TextView tv_drug_del3;
//	private TextView tv_drug_del4;

	private LinearLayout btn_patientsign;
	private ImageView img_patientsign;

	private RadioGroup shifang_group;//是否失访
	private RadioButton shifang_no;
	private RadioButton shifang_yes;

	private RadioGroup sflx_group;//随访类型
	private RadioButton sflx_zc;
	private RadioButton sflx_erci;

	private RadioGroup zhuanzhen_jieguo;//到位 不到位
	private RadioButton jieguo_no;
	private RadioButton jieguo_yes;

	private RadioGroup xybglcs_group;//下一步管理措施
	private RadioButton xybglcs1;
	private RadioButton xybglcs2;
	private RadioButton xybglcs3;
	private RadioButton xybglcs4;

	private EditText et_shifang;
	private EditText ed_zzphone;
	private EditText beizhu;

	String shifoushifang = "DM01-10_1";//是否失访
	String suifangleixing = "FOLLOW_UP_TYPE_1";// 随访类型
	String zhuanzhenjieguo = "ROLLOUT_RESULT_TYPE_1";// 随访类型
	String nextguanli = "NEXT_M_M_1";// 下一步管理措施

	private AutoCompleteTextView ed_ywmc11, ed_ywmc12, ed_ywmc13, ed_ywmc14;
	private AutoCompleteTextView ed_ywmc21, ed_ywmc22, ed_ywmc23, ed_ywmc24;
	private AutoCompleteTextView ed_ywmc31, ed_ywmc32, ed_ywmc33, ed_ywmc34;
	private AutoCompleteTextView ed_ywmc41, ed_ywmc42, ed_ywmc43, ed_ywmc44;
	private TextView tvdrug1, tvdrug2, tvdrug3, tvdrug4;
//	private TextView tvdrug01, tvdrug02, tvdrug03, tvdrug04;
//	private EditText drugTime1, drugTime2, drugTime3, drugTime4;

	private TextView tv_add_drug, tv_del_drug;
	private RecyclerView drugRecyclerView;
	private SfDrugAdapter sfDrugAdapter;
	// 用药情况数据
	private List<CD_DRUGCONDITION> sfDrugList = new ArrayList<>();

	private int id = -1;
	String sfWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";

	java.text.DecimalFormat weightdf = new java.text.DecimalFormat("#.0");

	public static GXY_SfFragment newInstance(int id) {
		GXY_SfFragment fragment = new GXY_SfFragment();
		Bundle args = new Bundle();
		args.putInt("id", id);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void setupView(View view) {
		if (getArguments() != null) {
			id = getArguments().getInt("id", -1);
			if (id != -1) {
				sfWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "' and id = '" + id + "'";
			} else {
				sfWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "' and id = '0'";
			}
		}

		listerDrugName();
		GlobalConts.setMaxLength(13, ed_xy);// 血压
		GlobalConts.setMaxLength(3, ed_xl, ed_rxyl, ed_xcsfmb_xy, ed_ryjl, ed_xcsfmb_yj, ed_yd_zq, ed_yd_min,
				ed_xcsfmb_yd_zq, ed_xcsfmb_yd_min);// 心率
		GlobalConts.setMaxLength(50, ed_qt, ed_fzjc, ed_zzyy, ed_jgkb);// 其他
		zhuanzhen_layout.setVisibility(View.VISIBLE);
//		GlobalConts.setMaxLength(35, ed_ywmc1, // 药物名称1
//				ed_ywmc2, // 药物名称2
//				ed_ywmc3, // 药物名称3
//				ed_qtyw);// 药物名称3
		setData();
		ed_tz.addTextChangedListener(new TextWatcher() {

			public void afterTextChanged(Editable edt) {
				try {
					String temp = edt.toString();
					int posDot = temp.indexOf(".");
					if (posDot <= 0)
						return;
					if (temp.length() - posDot - 1 > 1) {
						edt.delete(posDot + 2, posDot + 3);
					}

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			}

			public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
				if (ags.size() != 0) {
					if (arg0.toString().isEmpty() || TextUtils.isEmpty(ags.get(0).getHEIGHT())) {
						return;
					}

					double dh = Double.parseDouble(ags.get(0).getHEIGHT().toString()) / 100;
					Log.e("++++++++", ags.get(0).getHEIGHT().toString());
					double dw = Double.parseDouble(ed_tz.getText().toString());

					java.text.DecimalFormat df = new java.text.DecimalFormat("#.0");

					ed_tzzs.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
				}
			}
//			@Override
//			public void onTextChanged(CharSequence s, int start, int before, int count) {
//				if (!TextUtils.isEmpty(etHeight.getText().toString())) {
//					setBMI(etHeight, etWeight, etBMI);
//				}else{
//					etBMI.setText("");
//				}
//				if (TextUtils.isEmpty(s.toString())) {
//					etBMI.setText("");
//				}
//			}
//
//			@Override
//			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//				// TODO Auto-generated method stub
//
//			}
//
//			@Override
//			public void afterTextChanged(Editable s) {
//
//			}
		});
		ed_xcsfmb_tz.addTextChangedListener(new TextWatcher() {
			public void afterTextChanged(Editable edt) {
				try {
					String temp = edt.toString();
					int posDot = temp.indexOf(".");
					if (posDot <= 0)
						return;
					if (temp.length() - posDot - 1 > 1) {
						edt.delete(posDot + 2, posDot + 3);
					}


				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			}

			public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
				if (ags.size() != 0) {
					if (arg0.toString().isEmpty() || TextUtils.isEmpty(ags.get(0).getHEIGHT())) {
						return;
					}

					double dh = Double.parseDouble(ags.get(0).getHEIGHT().toString()) / 100;
					Log.e("++++++++", ags.get(0).getHEIGHT().toString());
					double dw = Double.parseDouble(ed_xcsfmb_tz.getText().toString());

					java.text.DecimalFormat df = new java.text.DecimalFormat("#.0");

					ed_tzzs_sf.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
				}
			}
		});
		try{
			List<SBCL_DATA> list1 = fdbmanger.findAllByWhere(SBCL_DATA.class,
					strWhere + "AND CL_TYPE_NAME = '高压' ORDER BY CL_TIME DESC LIMIT 1");

			List<SBCL_DATA> list2 = fdbmanger.findAllByWhere(SBCL_DATA.class,
					strWhere + "AND CL_TYPE_NAME = '低压' ORDER BY CL_TIME DESC LIMIT 1");

			if ((list1 != null && list1.size() > 0) && (list2 != null && list2.size() > 0)) {
				String gy = list1.get(0).getCL_VALUE().replace("mmHg","");
				String dy = list2.get(0).getCL_VALUE().replace("mmHg","");
				ed_xy.setText(gy +"/" + dy);
				int age = GlobalConts.getAge(userInfo.getBIRTHDAY());
				Double ssyd = Double.parseDouble(gy);
				Double szyd = Double.parseDouble(dy);
				if(age<65){
					if(ssyd>=140||szyd>=90){
						//此次随访分类，控制不满意
						nice_spinner_clsffl.setSelectedIndex(2);
					}else{
						//此次随访分类，控制满意
						nice_spinner_clsffl.setSelectedIndex(1);
					}
				}else{
					if(ssyd>=150||szyd>=90){
						//此次随访分类，控制不满意
						nice_spinner_clsffl.setSelectedIndex(2);
					}else{
						//此次随访分类，控制满意
						nice_spinner_clsffl.setSelectedIndex(1);
					}
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}

		try{
			List<SBCL_DATA> list3 = fdbmanger.findAllByWhere(SBCL_DATA.class,
					strWhere + "AND CL_TYPE_NAME = '脉率' AND DEVICE_TYPE = '血压计' ORDER BY CL_TIME DESC LIMIT 1");
			if (list3 != null && list3.size() > 0) {
				ed_xl.setText(list3.get(0).getCL_VALUE().replace("次/分",""));
			}
		}catch (Exception e) {
			e.printStackTrace();
		}

		try {
			List<SBCL_DATA> list4 = fdbmanger.findAllByWhere(SBCL_DATA.class,
					strWhere + "AND CL_TYPE_NAME = '体重' ORDER BY CL_TIME DESC LIMIT 1");
			if (list4 != null && list4.size() > 0) {
				String tizhong = list4.get(0).getCL_VALUE();
				if(tizhong.contains("lfWeightKg")){
					JSONObject obj = new JSONObject(tizhong);
					Double weight = obj.getDouble("lfWeightKg");
					ed_tz.setText(weightdf.format(weight));
				}else{
					ed_tz.setText(tizhong.replace("Kg",""));
				}



			}
		}catch (Exception e) {
			e.printStackTrace();
		}

		try {
			List<CD_HYPERTENSIONFOLLOWUP> gyxItemOne = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class,
					sfWhere,"ID DESC LIMIT 1");
			if (gyxItemOne != null && gyxItemOne.size() > 0) {
				ed_height.setText(gyxItemOne.get(0).getHeight());
			}else{
				List<SBCL_DATA> list4 = fdbmanger.findAllByWhere(SBCL_DATA.class,
						strWhere + "AND CL_TYPE_NAME = '身高' ORDER BY CL_TIME DESC LIMIT 1");
				if (list4 != null && list4.size() > 0) {
					ed_height.setText(list4.get(0).getCL_VALUE());
					setBMI(ed_height, ed_tz, ed_tzzs);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public View findViews(LayoutInflater inflater) {

		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		ags = fdbmanger.findAllByWhere(ARCHIVE_GENERALCONDITION.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
		cqsf2View = inflater.inflate(R.layout.gxy_sfxx, null);
		initViews(cqsf2View);

		return cqsf2View;
	}

	private void setDefaultValue() {
		adapter_zz.setChecked("DM04-02_000.0");
		ed_rxyl.setText("0");
		ed_xcsfmb_xy.setText("0");
		ed_ryjl.setText("0");
		ed_xcsfmb_yj.setText("0");
		nice_spinner_syqk.setSelectedIndex(1);
//		nice_spinner_syqk.setSelectedIndex(getListIndex("DM01-68_1", sy_list));
//		nice_spinner_xcsfmb.setSelectedIndex(getListIndex("DM01-68_1", sy_list));
		nice_spinner_xcsfmb.setSelectedIndex(1);
		nice_spinner_xltz.setSelectedIndex(2);
		nice_spinner_zyxw.setSelectedIndex(2);

		ed_qt.setText("无");
		ed_fzjc.setText("无");
		adapter_ywblfy.setChecked("DM01-11_1");
//		new Handler().postDelayed(new Runnable() {
//			@Override
//			public void run() {
//				nice_spinner_syqk.setSelectedIndex(1);
//				nice_spinner_xcsfmb.setSelectedIndex(2);
//			}
//		},5000);
	}

	private void listerDrugName() {
//		tvdrug01.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
//						.putExtra("type","gxy"),DRUG_NAME1);
//			}
//		});

//		tvdrug02.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
//						.putExtra("type","gxy"),DRUG_NAME2);
//			}
//		});
//		tvdrug03.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
//						.putExtra("type","gxy"),DRUG_NAME3);
//			}
//		});
//		tvdrug04.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
//						.putExtra("type","gxy"),DRUG_NAME4);
//			}
//		});

		tvdrug1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
						.putExtra("type","gxy"),DRUG_NAME11);
			}
		});

		tvdrug2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
						.putExtra("type","gxy"),DRUG_NAME21);
			}
		});

		tvdrug3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
						.putExtra("type","gxy"),DRUG_NAME31);
			}
		});
		tvdrug4.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
						.putExtra("type","gxy"),DRUG_NAME41);
			}
		});
	}

	// 患者签名
	private String strPatientSignPath = "";
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK) {
			switch (requestCode) {
				case DRUG_NAME1:
//					ed_ywmc1.setText("("+drug1.getProname()+")"+drug1.getDrugs());
					try {
						BD_DD_DRUG drug1 = (BD_DD_DRUG)data.getSerializableExtra("bean");
						int position = data.getIntExtra("position", 0);
						CD_DRUGCONDITION cdDrugcondition = sfDrugList.get(position);
						cdDrugcondition.setNAME("("+drug1.getProname()+")"+drug1.getDrugs());
						cdDrugcondition.setEVERYTIMEMG(drug1.getRes1());
						cdDrugcondition.setRES1(drug1.getRes2());
						cdDrugcondition.setRES3(drug1.getUsage());
						cdDrugcondition.setRES4(drug1.getDosage());
						cdDrugcondition.setDAILYTIME(drug1.getUsage() + "/" + drug1.getDosage());

						sfDrugAdapter.setNewData(sfDrugList);
						Log.e(TAG, "onActivityResult: "+ drug1 );
					} catch (NumberFormatException e) {
						e.printStackTrace();
					}
					break;
//				case DRUG_NAME2:
//					BD_DD_DRUG drug2 = (BD_DD_DRUG)data.getSerializableExtra("bean");
//					ed_ywmc2.setText("("+drug2.getProname()+")"+drug2.getDrugs());
//					try {
//						ed_ywmc2_mg.setText(drug2.getRes1());
//						nice_spinner_dw2.setText(drug2.getRes2());
//						nice_spinner_cc2.setText(drug2.getUsage());
//						nice_spinner_yl2.setText(drug2.getDosage());
//					} catch (NumberFormatException e) {
//						e.printStackTrace();
//					}
//					break;
//				case DRUG_NAME3:
//					BD_DD_DRUG drug3 = (BD_DD_DRUG)data.getSerializableExtra("bean");
//					ed_ywmc3.setText("("+drug3.getProname()+")"+drug3.getDrugs());
//					try {
//						ed_ywmc3_mg.setText(drug3.getRes1());
//						nice_spinner_dw3.setText(drug3.getRes2());
//						nice_spinner_cc3.setText(drug3.getUsage());
//						nice_spinner_yl3.setText(drug3.getDosage());
//					} catch (NumberFormatException e) {
//						e.printStackTrace();
//					}
//					break;
//				case DRUG_NAME4:
//					BD_DD_DRUG drug4 = (BD_DD_DRUG)data.getSerializableExtra("bean");
//					ed_qtyw.setText("("+drug4.getProname()+")"+drug4.getDrugs());
//					try {
//						ed_qtyw_mg.setText(drug4.getRes1());
//						nice_spinner_dwqt.setText(drug4.getRes2());
//						nice_spinner_cc4.setText(drug4.getUsage());
//						nice_spinner_yl4.setText(drug4.getDosage());
//					} catch (NumberFormatException e) {
//						e.printStackTrace();
//					}
//					break;
				case REQUEST_CODE_PHOTO:
					String path = data.getStringExtra("result"); // 图片地址
					Log.e(TAG, "onActivityResult: " + path );
					Glide.with(getActivity()).load(path).into(iv_paizhao_img);
					mPhotoPath = path;
					break;
				case REQUEST_CODE_PHOTO1:
					iv_paizhao_img.setBackground(new BitmapDrawable(null, ImageTools.readBitmapAutoSize(mPhotoPath)));
					break;
				case REQUEST_CODE_PHOTOqianming:
					if (data.getExtras().containsKey("filePath")) {
						strPatientSignPath = data.getExtras().getString("filePath");
						setSign(strPatientSignPath, img_patientsign);
//						patientsign = "重签";
					}
					break;
				case DRUG_NAME11:
					BD_DD_DRUG drug11 = (BD_DD_DRUG)data.getSerializableExtra("bean");
					ed_ywmc11.setText(notNull(drug11.getTjdrugname())); // 药品名称
					ed_ywmc12.setText(notNull(drug11.getTjyongfa())); // 用法
					ed_ywmc13.setText(notNull(drug11.getTjdosage())); // 用量
					ed_ywmc14.setText(notNull(drug11.getTjmcjl())); // 单位
					Log.e(TAG, "onActivityResult: "+ drug11);
					break;
				case DRUG_NAME21:
					BD_DD_DRUG drug21 = (BD_DD_DRUG)data.getSerializableExtra("bean");
					ed_ywmc21.setText(notNull(drug21.getTjdrugname()));
					ed_ywmc22.setText(notNull(drug21.getTjyongfa()));
					ed_ywmc23.setText(notNull(drug21.getTjdosage()));
					ed_ywmc24.setText(notNull(drug21.getTjmcjl()));
					Log.e(TAG, "onActivityResult: "+ drug21);
					break;
				case DRUG_NAME31:
					BD_DD_DRUG drug31 = (BD_DD_DRUG)data.getSerializableExtra("bean");
					ed_ywmc31.setText(notNull(drug31.getTjdrugname()));
					ed_ywmc32.setText(notNull(drug31.getTjyongfa()));
					ed_ywmc33.setText(notNull(drug31.getTjdosage()));
					ed_ywmc34.setText(notNull(drug31.getTjmcjl()));
					Log.e(TAG, "onActivityResult: "+ drug31);
					break;
				case DRUG_NAME41:
					BD_DD_DRUG drug41 = (BD_DD_DRUG)data.getSerializableExtra("bean");
					ed_ywmc41.setText(notNull(drug41.getTjdrugname()));
					ed_ywmc42.setText(notNull(drug41.getTjyongfa()));
					ed_ywmc43.setText(notNull(drug41.getTjdosage()));
					ed_ywmc44.setText(notNull(drug41.getTjmcjl()));
					Log.e(TAG, "onActivityResult: "+ drug41);
					break;
			}
		}
	}

	@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
	private void setSign(String imgPath, ImageView v) {
		// String result = "";

		if (!TextUtils.isEmpty(imgPath)) {
			Log.e(TAG, "照片src：" + imgPath);
			File file = new File(imgPath);
			if (file.exists()) {
				// v.setbacImageBitmap(ImageTools.readBitmapAutoSize(imgPath));
				v.setVisibility(View.VISIBLE);
				v.setBackground(new BitmapDrawable(null, ImageTools.readBitmapAutoSize(imgPath)));
			} else {
				v.setImageBitmap(null);
			}
		}
	}


	/**
	 * 初始化布局
	 *
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月21日 上午11:10:55
	 */
	private void initViews(View v) {
//		drugTime1 = v.findViewById(R.id.drugTime1);
//		drugTime2 = v.findViewById(R.id.drugTime2);
//		drugTime3 = v.findViewById(R.id.drugTime3);
//		drugTime4 = v.findViewById(R.id.drugTime4);
//		tvdrug01 = v.findViewById(R.id.tvdrug01);
//		tvdrug02 = v.findViewById(R.id.tvdrug02);
//		tvdrug03 = v.findViewById(R.id.tvdrug03);
//		tvdrug04 = v.findViewById(R.id.tvdrug04);

		tvdrug1 = v.findViewById(R.id.tvdrug1);
		tvdrug2 = v.findViewById(R.id.tvdrug2);
		tvdrug3 = v.findViewById(R.id.tvdrug3);
		tvdrug4 = v.findViewById(R.id.tvdrug4);
		ed_ywmc11 = v.findViewById(R.id.ed_ywmc11);
		ed_ywmc12 = v.findViewById(R.id.ed_ywmc12);
		ed_ywmc13 = v.findViewById(R.id.ed_ywmc13);
		ed_ywmc14 = v.findViewById(R.id.ed_ywmc14);

		ed_ywmc21 = v.findViewById(R.id.ed_ywmc21);
		ed_ywmc22 = v.findViewById(R.id.ed_ywmc22);
		ed_ywmc23 = v.findViewById(R.id.ed_ywmc23);
		ed_ywmc24 = v.findViewById(R.id.ed_ywmc24);

		ed_ywmc31 = v.findViewById(R.id.ed_ywmc31);
		ed_ywmc32 = v.findViewById(R.id.ed_ywmc32);
		ed_ywmc33 = v.findViewById(R.id.ed_ywmc33);
		ed_ywmc34 = v.findViewById(R.id.ed_ywmc34);

		ed_ywmc41 = v.findViewById(R.id.ed_ywmc41);
		ed_ywmc42 = v.findViewById(R.id.ed_ywmc42);
		ed_ywmc43 = v.findViewById(R.id.ed_ywmc43);
		ed_ywmc44 = v.findViewById(R.id.ed_ywmc44);

		shifang_group = v.findViewById(R.id.shifang_group);
		shifang_no = v.findViewById(R.id.shifang_no);
		shifang_yes = v.findViewById(R.id.shifang_yes);
		sflx_group = v.findViewById(R.id.sflx_group);
		sflx_zc = v.findViewById(R.id.sflx_zc);
		sflx_erci = v.findViewById(R.id.sflx_erci);
		zhuanzhen_jieguo = v.findViewById(R.id.zhuanzhen_jieguo);
		jieguo_no = v.findViewById(R.id.jieguo_no);
		jieguo_yes = v.findViewById(R.id.jieguo_yes);
		xybglcs_group = v.findViewById(R.id.xybglcs_group);
		xybglcs1 = v.findViewById(R.id.xybglcs1);
		xybglcs2 = v.findViewById(R.id.xybglcs2);
		xybglcs4 = v.findViewById(R.id.xybglcs4);
		xybglcs3 = v.findViewById(R.id.xybglcs3);
		et_shifang = v.findViewById(R.id.et_shifang);
		ed_zzphone = v.findViewById(R.id.ed_zzphone);
		beizhu = v.findViewById(R.id.beizhu);

		btn_patientsign = v.findViewById(R.id.btn_patientsign);
		img_patientsign = (ImageView) v.findViewById(R.id.img_patientsign);
		btn_patientsign.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 患者签名btn
				Intent intent = new Intent(getActivity(), QianMingActivity.class);
				// //命名规则： 身份证号_签约时间_用户类型_创建时间时分秒_随机数.png[用户类型： 1 医生 2 患者 3
				// 其他图片]
				intent.putExtra(QianMingActivity.SIGNNAME_HEAD, getPhotoPath());
				startActivityForResult(intent, REQUEST_CODE_PHOTOqianming);
			}
		});
		bt_paizhao = v.findViewById(R.id.bt_paizhao);
		iv_paizhao_img = v.findViewById(R.id.iv_paizhao_img);
		ed_date = (EditTextWithDate2) v.findViewById(R.id.ed_date);
		ed_sfys = (NiceSpinner) v.findViewById(R.id.ed_sfys);
		nice_spinner_szfs = (NiceSpinner) v.findViewById(R.id.nice_spinner_szfs);

		gd_zz = (MyGridView) v.findViewById(R.id.gd_zz);

		ed_xy = (EditText) v.findViewById(R.id.ed_xy);
		btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);
		btn_choose_xl=(Button)v.findViewById(R.id.btn_choose_xl);

		ed_xl = (EditText) v.findViewById(R.id.ed_xl);
		ed_tz = (EditText) v.findViewById(R.id.ed_tz);
		btn_choose_tz = (Button) v.findViewById(R.id.btn_choose_tz);
		ed_xcsfmb_tz = (EditText) v.findViewById(R.id.ed_xcsfmb_tz);

		ed_tzzs = (EditText) v.findViewById(R.id.ed_tzzs);
		ed_height = (EditText) v.findViewById(R.id.ed_height);
		ed_tzzs_sf = (EditText) v.findViewById(R.id.ed_tzzs_sf);
		ed_qt = (EditText) v.findViewById(R.id.ed_qt);
		ed_rxyl = (EditText) v.findViewById(R.id.ed_rxyl);
		ed_xcsfmb_xy = (EditText) v.findViewById(R.id.ed_xcsfmb_xy);
		ed_ryjl = (EditText) v.findViewById(R.id.ed_ryjl);

		ed_xcsfmb_yj = (EditText) v.findViewById(R.id.ed_xcsfmb_yj);
		syqk_edt=v.findViewById(R.id.syqk_edt);
		ed_yd_zq = (EditText) v.findViewById(R.id.ed_yd_zq);
		ed_yd_min = (EditText) v.findViewById(R.id.ed_yd_min);
		ed_xcsfmb_yd_zq = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_zq);
		ed_xcsfmb_yd_min = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_min);
		nice_spinner_syqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_syqk);
		nice_spinner_xcsfmb = (NiceSpinner) v.findViewById(R.id.nice_spinner_xcsfmb);
		nice_spinner_xltz = (NiceSpinner) v.findViewById(R.id.nice_spinner_xltz);
		nice_spinner_zyxw = (NiceSpinner) v.findViewById(R.id.nice_spinner_zyxw);

		ed_fzjc = (EditText) v.findViewById(R.id.ed_fzjc);
		nice_spinner_fyycx = (NiceSpinner) v.findViewById(R.id.nice_spinner_fyycx);
		gd_ywblfy = (MyGridView) v.findViewById(R.id.gd_ywblfy);

		nice_spinner_clsffl = (NiceSpinner) v.findViewById(R.id.nice_spinner_clsffl);
//		ed_ywmc1 =  v.findViewById(R.id.ed_ywmc1);
//		ed_ywmc1_day = (EditText) v.findViewById(R.id.ed_ywmc1_day);
//		ed_ywmc1_mg = (EditText) v.findViewById(R.id.ed_ywmc1_mg);
//		ed_ywmc2 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc2);
//		ed_ywmc2_day = (EditText) v.findViewById(R.id.ed_ywmc2_day);
//		ed_ywmc2_mg = (EditText) v.findViewById(R.id.ed_ywmc2_mg);
//		ed_ywmc3 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc3);
//		ed_ywmc3_day = (EditText) v.findViewById(R.id.ed_ywmc3_day);
//		ed_ywmc3_mg = (EditText) v.findViewById(R.id.ed_ywmc3_mg);

//		ed_qtyw = (AutoCompleteTextView) v.findViewById(R.id.ed_qtyw);
//		ed_qtyw_day = (EditText) v.findViewById(R.id.ed_qtyw_day);
//		ed_qtyw_mg = (EditText) v.findViewById(R.id.ed_qtyw_mg);
		ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);
		ed_jgkb = (EditText) v.findViewById(R.id.ed_jgkb);
		ed_xcsfsj = (EditTextWithDate2) v.findViewById(R.id.ed_xcsfsj);
//		nice_spinner_dw1 =  v.findViewById(R.id.nice_spinner_dw1);
//		nice_spinner_dw2 =  v.findViewById(R.id.nice_spinner_dw2);
//		nice_spinner_dw3 =  v.findViewById(R.id.nice_spinner_dw3);
//		nice_spinner_dwqt = v.findViewById(R.id.nice_spinner_dwqt);
//		nice_spinner_cc1 = v.findViewById(R.id.nice_spinner_cc1);
//		nice_spinner_cc2 = v.findViewById(R.id.nice_spinner_cc2);
//		nice_spinner_cc3 = v.findViewById(R.id.nice_spinner_cc3);
//		nice_spinner_cc4 = v.findViewById(R.id.nice_spinner_cc4);
//		nice_spinner_yl1 = v.findViewById(R.id.nice_spinner_yl1);
//		nice_spinner_yl2 = v.findViewById(R.id.nice_spinner_yl2);
//		nice_spinner_yl3 = v.findViewById(R.id.nice_spinner_yl3);
//		nice_spinner_yl4 = v.findViewById(R.id.nice_spinner_yl4);

//		tv_drug_del1 = (TextView) v.findViewById(R.id.tv_drug_del1);
//		tv_drug_del2 = (TextView) v.findViewById(R.id.tv_drug_del2);
//		tv_drug_del3 = (TextView) v.findViewById(R.id.tv_drug_del3);
//		tv_drug_del4 = (TextView) v.findViewById(R.id.tv_drug_del4);
//
//		tv_drug_del1.setOnClickListener(v1 -> {
//			ed_ywmc1.setText("");
//		});
//		tv_drug_del2.setOnClickListener(v1 -> {
//			ed_ywmc2.setText("");
//		});
//		tv_drug_del3.setOnClickListener(v1 -> {
//			ed_ywmc3.setText("");
//		});
//		tv_drug_del4.setOnClickListener(v1 -> {
//			ed_qtyw.setText("");
//		});

		ed_date.setBefore(true);
//		String threeTime = getThreeTime();
//		ed_xcsfsj.setText(threeTime);
		ed_xcsfsj.setAfter(true,0);
		zhuanzhen_group=v.findViewById(R.id.zhuanzhen_group);
		zhuanzhen_no=v.findViewById(R.id.zhuanzhen_no);
		zhuanzhen_yes=v.findViewById(R.id.zhuanzhen_yes);
		zhuanzhen_layout=v.findViewById(R.id.zhuanzhen_layout);
		jiankangjianyi=v.findViewById(R.id.jiankangjianyi);
		drugRecyclerView = v.findViewById(R.id.drugRecyclerView);
		tv_add_drug = v.findViewById(R.id.tv_add_drug);
		tv_del_drug = v.findViewById(R.id.tv_del_drug);

		// 创建一个ArrayAdapter，封装数组
		ArrayAdapter<String> arr = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line,
				gxy_yws);

//		ed_ywmc1.setAdapter(arr);
//		ed_ywmc2.setAdapter(arr);
//		ed_ywmc3.setAdapter(arr);
//		ed_qtyw.setAdapter(arr);


		initAdapter();

		nice_spinner_clsffl.addOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if ("控制不满意".equals(ccsffl_list.get(position).getDATAINFO())) {
					try {
						Log.e(TAG, "onItemClick: "+ ed_date.getDate() );
						Calendar calendar = Calendar.getInstance(); //得到日历
						calendar.setTime(dateFormat.parse(ed_date.getText().toString()));//把当前时间赋给日历
						calendar.add(Calendar.DATE, 14);
						ed_xcsfsj.setText(dateFormat.format(calendar.getTime()));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}else if ("控制满意".equals(ccsffl_list.get(position).getDATAINFO())){
					try {
						Log.e(TAG, "onItemClick: "+ ed_date.getDate());
						Calendar calendar = Calendar.getInstance(); //得到日历
						calendar.setTime(dateFormat.parse(ed_date.getText().toString()));//把当前时间赋给日历
						calendar.add(Calendar.MONTH, 3);  //设置为前3月
						ed_xcsfsj.setText(dateFormat.format(calendar.getTime()));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		});

	}

	private void initAdapter() {
		sfDrugAdapter = new SfDrugAdapter(R.layout.item_sf_drug_list, sfDrugList);
		drugRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
		drugRecyclerView.setAdapter(sfDrugAdapter);

		tv_add_drug.setOnClickListener(v -> {
			CD_DRUGCONDITION cdDrugcondition = new CD_DRUGCONDITION();
			cdDrugcondition.setNAME("");
			cdDrugcondition.setRES1("");
			cdDrugcondition.setRES2("");
			cdDrugcondition.setRES3("");
			cdDrugcondition.setRES4("");
			cdDrugcondition.setEVERYTIMEMG("");
			cdDrugcondition.setDAILYTIME("");

			sfDrugList.add(cdDrugcondition);
			sfDrugAdapter.setNewData(sfDrugList);
			sfDrugAdapter.notifyDataSetChanged();
		});
		tv_del_drug.setOnClickListener(v -> {
			if (sfDrugList.size() > 0) {
				sfDrugList.remove(sfDrugList.size() - 1);
				sfDrugAdapter.setNewData(sfDrugList);
				sfDrugAdapter.notifyDataSetChanged();
			}
		});

		sfDrugAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
			@Override
			public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
				if (view.getId() == R.id.tvdrug) {
					startActivityForResult(new Intent(getActivity(), QueryDrugListActivity.class)
						.putExtra("type","gxy")
						.putExtra("position", position)
							, DRUG_NAME1);
				}
			}
		});
	}

	/**
	 * 绑定数据值
	 *
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);
		if (flag.equals("症状")) {
			int size = listZZs.size();
			List<BD_DD_INFO> bd_zzs;
			if (size > 0) {
				bd_zzs = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = listZZs.get(i).getID();
					if (str_id.equals("DM04-02_R42.x") || str_id.equals("DM04-02_H93.1")) {

					} else {
						bd_zzs.add(listZZs.get(i));
					}
				}
				adapter_zz = new CheckBoxAdapter(getActivity(), bd_zzs);

			}
			gd_zz.setAdapter(adapter_zz);
		} else if (flag.equals("药物不良反应")) {
			adapter_ywblfy = new RadioButtonAdapter(listZZs, getActivity());
			adapter_ywblfy.setOtherMaxLength(50);
			gd_ywblfy.setAdapter(adapter_ywblfy);
		}

	}

	/**
	 * 设置下拉
	 *
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
		BD_DD_INFO bd = new BD_DD_INFO();
		bd.setDATAINFO("请选择");
		bd.setID("");
		sList.add(bd);

		List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				strSql + " order by cast(SORT as int) asc");
		sList.addAll(sList1);
		if (flagName.equals("摄盐")) {
			sy_list = sList;
			nice_spinner_syqk.attachDataSource(sy_list);

		} else if (flagName.equals("下次随访目标")) {
			xcsfmb_list = sList;
			nice_spinner_xcsfmb.attachDataSource(xcsfmb_list);

		} else if (flagName.equals("心理情况")) {

			int size = sList.size();
			if (size > 0) {
				xltz_list = new ArrayList<BD_DD_INFO>();
				zyxw_list = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = sList.get(i).getID();
					if (str_id.equals("DM01-69_1") || str_id.equals("DM01-69_2") || str_id.equals("DM01-69_3")
							|| str_id.equals("")) {
						xltz_list.add(sList.get(i));
						zyxw_list.add(sList.get(i));
					}
				}
			}

			nice_spinner_xltz.attachDataSource(xltz_list);
			nice_spinner_zyxw.attachDataSource(zyxw_list);
		} else if (flagName.equals("药物依从性")) {
			ywycx_list = sList;
			nice_spinner_fyycx.attachDataSource(ywycx_list);
		} else if (flagName.equals("此次随访分类")) {
			int size = sList.size();
			if (size > 0) {
				ccsffl_list = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = sList.get(i).getID();
					if (str_id.equals("DM01-71_1") || str_id.equals("DM01-71_2") || str_id.equals("DM01-71_3")
							|| str_id.equals("DM01-71_4") || str_id.equals("")) {
						ccsffl_list.add(sList.get(i));
					}
				}
			}

			nice_spinner_clsffl.attachDataSource(ccsffl_list);
		} else if (flagName.equals("随诊方式")) {
			szfs_list = sList;
			nice_spinner_szfs.attachDataSource(szfs_list);
		} else if (flagName.equals("药物单位")) {
			ywdw_list = sList1;
//			nice_spinner_dw1.attachDataSource(sList1);
//			nice_spinner_dw2.attachDataSource(sList1);
//			nice_spinner_dw3.attachDataSource(sList1);
//			nice_spinner_dwqt.attachDataSource(sList1);
		}

	}


	@Override
	public void addListener() {
		btn_choose_xy.setOnClickListener(this);
		btn_choose_tz.setOnClickListener(this);
		btn_choose_xl.setOnClickListener(this);
		bt_paizhao.setOnClickListener(this);
		changeBMI(ed_height, ed_tz, ed_tzzs);
//		changeBMI(ed_height, ed_xcsfmb_tz, ed_tzzs_sf);
		int age = GlobalConts.getAge(userInfo.getBIRTHDAY());

		ed_xy.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (!hasFocus) {
					// EditText失去焦点时的处理逻辑
					String str_xy = ed_xy.getText().toString();
					if (!TextUtils.isEmpty(str_xy)) {
						if (str_xy.contains("/")) {
							if (str_xy.split("/").length == 2) {
								String[] split = str_xy.split("/");
								String ssy = split[0];// 收缩压
								String szy = split[1];// 舒张压
								Double ssyd = Double.parseDouble(ssy);
								Double szyd = Double.parseDouble(szy);
								if(age<65){
									if(ssyd>=140||szyd>=90){
										//此次随访分类，控制不满意
//										readFollowup.setFOLLOWUPTYPE("DM01-71_2");
										nice_spinner_clsffl.setSelectedIndex(2);
									}else{
										//此次随访分类，控制满意
//										readFollowup.setFOLLOWUPTYPE("DM01-71_1");
										nice_spinner_clsffl.setSelectedIndex(1);
									}
								}else{
									if(ssyd>=150||szyd>=90){
										//此次随访分类，控制不满意
//										readFollowup.setFOLLOWUPTYPE("DM01-71_2");
										nice_spinner_clsffl.setSelectedIndex(2);
									}else{
										//此次随访分类，控制满意
//										readFollowup.setFOLLOWUPTYPE("DM01-71_1");
										nice_spinner_clsffl.setSelectedIndex(1);
									}
								}
							}
						}
					}
				}
			}
		});


//		zhuanzhen_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//			@Override
//			public void onCheckedChanged(RadioGroup group, int checkedId) {
//				if(checkedId==zhuanzhen_no.getId()){
//					zhuanzhen_layout.setVisibility(View.GONE);
//					isREFERRAL="DM01-11_1";
//					ed_zzyy.setText("");
//					ed_jgkb.setText("");
//				}else if(checkedId==zhuanzhen_yes.getId()){
//					isREFERRAL="DM01-11_2";
//					zhuanzhen_layout.setVisibility(View.VISIBLE);
//				}
//			}
//		});

		shifang_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==shifang_no.getId()){
					shifoushifang="DM01-10_1";
				}else if(checkedId==shifang_yes.getId()){
					shifoushifang="DM01-10_2";
				}
			}
		});

		sflx_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==sflx_zc.getId()){
					suifangleixing="FOLLOW_UP_TYPE_1";
				}else if(checkedId==sflx_erci.getId()){
					suifangleixing="FOLLOW_UP_TYPE_2";
				}
			}
		});

		zhuanzhen_jieguo.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==jieguo_no.getId()){
					zhuanzhenjieguo="ROLLOUT_RESULT_TYPE_1";
				}else if(checkedId==jieguo_yes.getId()){
					zhuanzhenjieguo="ROLLOUT_RESULT_TYPE_2";
				}
			}
		});

		xybglcs_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==xybglcs1.getId()){
					nextguanli="NEXT_M_M_1";
				}else if(checkedId==xybglcs2.getId()){
					nextguanli="NEXT_M_M_2";
				}else if(checkedId==xybglcs3.getId()){
					nextguanli="NEXT_M_M_3";
				}else if(checkedId==xybglcs4.getId()){
					nextguanli="NEXT_M_M_4";
				}
			}
		});
		ed_tz.addTextChangedListener(new TextWatcher() {

			public void afterTextChanged(Editable edt) {
				try {
					String temp = edt.toString();
					int posDot = temp.indexOf(".");
					if (posDot <= 0)
						return;
					if (temp.length() - posDot - 1 > 1) {
						edt.delete(posDot + 2, posDot + 3);
					}

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			}

			public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
				if (ags.size() != 0) {
					if (arg0.toString().isEmpty() || TextUtils.isEmpty(ags.get(0).getHEIGHT())) {
						return;
					}

					double dh = Double.parseDouble(ags.get(0).getHEIGHT().toString()) / 100;
					Log.e("++++++++", ags.get(0).getHEIGHT().toString());
					double dw = Double.parseDouble(ed_tz.getText().toString());

					java.text.DecimalFormat df = new java.text.DecimalFormat("#.0");

					ed_tzzs.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
					setBMI(ed_height, ed_tz, ed_tzzs);
				}
			}
		});
//		setDefaultValue();
	}

	/**
	 * 身高或者体重改变时，BMI的值随之发生改变
	 **/
	private void changeBMI(final EditText etHeight, final EditText etWeight, final EditText etBMI) {
		etHeight.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if (!TextUtils.isEmpty(etWeight.getText().toString())) {
					setBMI(etHeight, etWeight, etBMI);
				}else{
					etBMI.setText("");
				}

				if (TextUtils.isEmpty(s.toString())) {
					etBMI.setText("");
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
		etWeight.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if (!TextUtils.isEmpty(etWeight.getText().toString())) {
					setBMI(etHeight, etWeight, etBMI);
				}else{
					etBMI.setText("");
				}

				if (TextUtils.isEmpty(s.toString())) {
					etBMI.setText("");
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});

	}

	/**
	 * 设置BMI
	 *
	 * @author 王婷婷
	 * @date 2017年4月5日 上午10:48:51
	 */
	private void setBMI(EditText etHeight, EditText etWeight, EditText etBMI) {
		try {
			if (TextUtils.isEmpty(etHeight.getText().toString()) || TextUtils.isEmpty(etHeight.getText().toString())) {
				etBMI.setText("");
				return;
			}

			double dh = Double.parseDouble(etHeight.getText().toString()) / 100;
//			double dw = Double.parseDouble(etWeight.getText().toString());

			double dw = Math.floor(Double.parseDouble(etWeight.getText().toString()) * 10) / 10;
			dw = Double.parseDouble(weightdf.format(dw));
			java.text.DecimalFormat df = new java.text.DecimalFormat("#.0");
			Double bmi = GlobalConts.getBMI(dh, dw);
			etBMI.setText(df.format(bmi) + "");
			if(bmi>=24){
				Double xctz = dw-3;

				ed_xcsfmb_tz.setText(df.format(xctz));
				ed_tzzs_sf.setText(df.format(GlobalConts.getBMI(dh, xctz))+"");
			}else{
				ed_xcsfmb_tz.setText(etWeight.getText().toString());
				ed_tzzs_sf.setText(df.format(bmi) + "");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}


	@Override
	public void setData() {
		try {

			// TODO
			bindDdata("症状", "PARENTID='DM04-02'");
			bindDdata("药物不良反应", "PARENTID='DM01-11'");

			bindSpinner("摄盐", "PARENTID='DM01-68'");
			bindSpinner("下次随访目标", "PARENTID='DM01-68'");
			bindSpinner("心理情况", "PARENTID='DM01-69'");
			bindSpinner("药物依从性", "PARENTID='DM01-70'");
			bindSpinner("此次随访分类", "PARENTID='DM01-71'");
			bindSpinner("随诊方式", "PARENTID='DM04-15'");
			bindSpinner("药物单位", "PARENTID='DM04-05'");
			GlobalConts.doctorList(ed_sfys);
			setDBData();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private int fromCD_HY = 0;
	private int fromCD_DR = 0;

	private void setDBData() {
		List<CD_HYPERTENSIONFOLLOWUP> list = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class,
				sfWhere,"ID DESC LIMIT 1");

		ccList = new ArrayList<String>();
		ccList.add("口服");
		ccList.add("直肠用药");
		ccList.add("舌下用药");
		ccList.add("注射用药");
		ccList.add("吸入用药");
		ccList.add("局部用药");

		ccList.add("皮下注射");
		ccList.add("皮内注射");
		ccList.add("其它途径");
		ccList.add("滴眼");
		ccList.add("喷喉");
		ccList.add("滴鼻");
		ccList.add("含化");
		ccList.add("敷伤口");
		ccList.add("擦皮肤");
		ccList.add("胸膜腔用药");
		ccList.add("腹腔用药");
		ccList.add("阴道用药");
		ccList.add("推管内用药");
		ccList.add("气管内用药");

		ccList.add("关节腔内用药");
		ccList.add("肌肉注射");
		ccList.add("静脉注射或静脉滴注");
		ccList.add("其他局部用药");

//		nice_spinner_cc1.attachDataSource(ccList);
//		nice_spinner_cc2.attachDataSource(ccList);
//		nice_spinner_cc3.attachDataSource(ccList);
//		nice_spinner_cc4.attachDataSource(ccList);

		ylList = new ArrayList<String>();
		ylList.add("一日一次");
		ylList.add("一日两次");
		ylList.add("一日三次");
		ylList.add("一日四次");
		ylList.add("一周一次");
		ylList.add("一周两次");
		ylList.add("一周三次");
		ylList.add("一周四次");
		ylList.add("一日两次");
		ylList.add("一周两次");
//			ylList.add("睡前服用");
//			ylList.add("12小时一次");
//			ylList.add("1小时一次");
//			ylList.add("3小时一次");
//			ylList.add("6小时一次");
//			ylList.add("一日三次");
//			ylList.add("一日一次");
//			ylList.add("一日四次");
//			ylList.add("隔日一次");
//			ylList.add("一周一次");
//			ylList.add("一周两次");
//			ylList.add("立即服用");
		ylList.add("其他");
//		nice_spinner_yl1.attachDataSource(ylList);
//		nice_spinner_yl2.attachDataSource(ylList);
//		nice_spinner_yl3.attachDataSource(ylList);
//		nice_spinner_yl4.attachDataSource(ylList);

		setDefaultValue();
		Log.e(TAG,"查询大小："+list.size());
		if (list.size() > 0) {
			fromCD_HY = 1;
			readFollowup = list.get(0);
			ed_date.setDate(readFollowup.getFOLLOWUPDATE());
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (NovaApplication.getDoctorList().get(i).getUSER_ID().equals(readFollowup.getFOLLOWUPDOCTOR())) {
					ed_sfys.setSelectedIndex(i);
				}

			}
			String symptoms = readFollowup.getSYMPTOM();
			adapter_zz.setChecked(symptoms);
			adapter_zz.setOther(readFollowup.getSYMPTOMOTHER());
			if (readFollowup.getFOLLOWUPWAY().contains("DM04-04")){
				nice_spinner_szfs.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPWAY().replace("DM04-04","DM04-15"), szfs_list));
			}else{
				nice_spinner_szfs.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPWAY(), szfs_list));
			}


			if (!TextUtils.isEmpty(readFollowup.getHYPERTENSION())) {
				if ((!TextUtils.isEmpty(readFollowup.getHYPERTENSION()))
						&& (!TextUtils.isEmpty(readFollowup.getHYPOTENSION()))) {
				}
				Log.e(TAG, "111setDBData: " + readFollowup.getHYPERTENSION() + "/" + readFollowup.getHYPOTENSION());
				ed_xy.setText(notNull(readFollowup.getHYPERTENSION() + "/" + readFollowup.getHYPOTENSION()));
			}else {

			}
			ed_xl.setText(notNull(readFollowup.getHEARTRATE()));
			ed_tz.setText(notNull(readFollowup.getWEIGHT()));
			ed_xcsfmb_tz.setText(notNull(readFollowup.getWEIGHTTARGET()));

//			ed_tzzs.setText(GlobalConts.getFormattedBMI(notNull(readFollowup.getBMI())));
			ed_height.setText(notNull(readFollowup.getHeight()));
			setBMI(ed_height, ed_tz, ed_tzzs);
			setBMI(ed_height, ed_tz, ed_tzzs_sf);
//			ed_tzzs_sf.setText(GlobalConts.getFormattedBMI(notNull(readFollowup.getBMITARGET())));
			ed_qt.setText(notNull(readFollowup.getPHYSICALSYMPTOMOTHER()));
			if(!TextUtils.isEmpty(readFollowup.getISREFERRAL())){
				isREFERRAL = readFollowup.getISREFERRAL();
				if("DM01-11_1".equals(readFollowup.getISREFERRAL())){
					zhuanzhen_no.setChecked(true);
					zhuanzhen_yes.setChecked(false);
//					zhuanzhen_layout.setVisibility(View.GONE);
				}else if("DM01-11_2".equals(readFollowup.getISREFERRAL())){
					zhuanzhen_yes.setChecked(true);
					zhuanzhen_no.setChecked(false);
//					zhuanzhen_layout.setVisibility(View.VISIBLE);
				}

			}
			zhuanzhen_layout.setVisibility(View.VISIBLE);

			if(!TextUtils.isEmpty(readFollowup.getRes11())){
				shifoushifang = readFollowup.getRes11();
				if("DM01-10_1".equals(readFollowup.getRes11())){
					shifang_no.setChecked(true);
					shifang_yes.setChecked(false);
				}else if("DM01-10_2".equals(readFollowup.getRes11())){
					shifang_yes.setChecked(true);
					shifang_no.setChecked(false);
				}
			}
			if(!TextUtils.isEmpty(readFollowup.getRes13())){
				suifangleixing = readFollowup.getRes13();
				if("FOLLOW_UP_TYPE_1".equals(readFollowup.getRes13())){
					sflx_zc.setChecked(true);
					sflx_erci.setChecked(false);
				}else if("FOLLOW_UP_TYPE_2".equals(readFollowup.getRes13())){
					sflx_erci.setChecked(true);
					sflx_zc.setChecked(false);
				}
			}
			if(!TextUtils.isEmpty(readFollowup.getRes15())){
				zhuanzhenjieguo = readFollowup.getRes15();
				if("ROLLOUT_RESULT_TYPE_1".equals(readFollowup.getRes15())){
					jieguo_no.setChecked(true);
					jieguo_yes.setChecked(false);
				}else if("ROLLOUT_RESULT_TYPE_2".equals(readFollowup.getRes15())){
					jieguo_yes.setChecked(true);
					jieguo_no.setChecked(false);
				}
			}
			if(!TextUtils.isEmpty(readFollowup.getRes16())){
				nextguanli = readFollowup.getRes16();
				if("NEXT_M_M_1".equals(readFollowup.getRes16())){
					xybglcs1.setChecked(true);
					xybglcs2.setChecked(false);
					xybglcs3.setChecked(false);
					xybglcs4.setChecked(false);
				}else if("NEXT_M_M_2".equals(readFollowup.getRes16())){
					xybglcs1.setChecked(false);
					xybglcs2.setChecked(true);
					xybglcs3.setChecked(false);
					xybglcs4.setChecked(false);
				}else if("NEXT_M_M_3".equals(readFollowup.getRes16())){
					xybglcs1.setChecked(false);
					xybglcs2.setChecked(false);
					xybglcs3.setChecked(true);
					xybglcs4.setChecked(false);
				}else if("NEXT_M_M_4".equals(readFollowup.getRes16())){
					xybglcs1.setChecked(false);
					xybglcs2.setChecked(false);
					xybglcs3.setChecked(false);
					xybglcs4.setChecked(true);
				}
			}
			et_shifang.setText(notNull(readFollowup.getRes12()));
			ed_zzphone.setText(notNull(readFollowup.getRes14()));
			beizhu.setText(notNull(readFollowup.getRes18()));

			ed_ywmc11.setText(notNull(readFollowup.getDrug11()));
			ed_ywmc12.setText(notNull(readFollowup.getDrug12()));
			ed_ywmc13.setText(notNull(readFollowup.getDrug13()));
			ed_ywmc14.setText(notNull(readFollowup.getDrug14()));
			ed_ywmc21.setText(notNull(readFollowup.getDrug21()));
			ed_ywmc22.setText(notNull(readFollowup.getDrug22()));
			ed_ywmc23.setText(notNull(readFollowup.getDrug23()));
			ed_ywmc24.setText(notNull(readFollowup.getDrug24()));
			ed_ywmc31.setText(notNull(readFollowup.getDrug31()));
			ed_ywmc32.setText(notNull(readFollowup.getDrug32()));
			ed_ywmc33.setText(notNull(readFollowup.getDrug33()));
			ed_ywmc34.setText(notNull(readFollowup.getDrug34()));
			ed_ywmc41.setText(notNull(readFollowup.getDrug41()));
			ed_ywmc42.setText(notNull(readFollowup.getDrug42()));
			ed_ywmc43.setText(notNull(readFollowup.getDrug43()));
			ed_ywmc44.setText(notNull(readFollowup.getDrug44()));

			jiankangjianyi.setText(notNull(readFollowup.getHEALTH_ASSESS()));

			ed_rxyl.setText(notNull(readFollowup.getDAILYSMOKENUM()));
			ed_xcsfmb_xy.setText(notNull(readFollowup.getDAILYSMOKENUMTARGET()));
			ed_ryjl.setText(notNull(readFollowup.getDAILYDRINKNUM()));
			ed_xcsfmb_yj.setText(notNull(readFollowup.getDAILYDRINKNUMTARGET()));
			syqk_edt.setText(notNull(readFollowup.getTOSALT()));
			ed_yd_zq.setText(notNull(readFollowup.getSPORTTIMEPERWEEK()));
			ed_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTETIME()));
			ed_xcsfmb_yd_zq.setText(notNull(readFollowup.getSPORTTIMESPERWEEKTARGET()));
			ed_xcsfmb_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTESTIMETARGET()));
			ed_fzjc.setText(readFollowup.getASSISTANTEXAM());
			System.out.println(readFollowup.getEATSALTTYPE() + "************");
			nice_spinner_syqk.setSelectedIndex(getListIndex(readFollowup.getEATSALTTYPE(), sy_list));
			nice_spinner_xcsfmb.setSelectedIndex(getListIndex(readFollowup.getEATSALTTARGET(), xcsfmb_list));
			nice_spinner_xltz.setSelectedIndex(getListIndex(readFollowup.getPSYCHOADJUSTMENT(), xltz_list));
			nice_spinner_zyxw.setSelectedIndex(getListIndex(readFollowup.getOBEYDOCTORBEHAVIOR(), zyxw_list));
			nice_spinner_clsffl.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPTYPE(), ccsffl_list));
			nice_spinner_fyycx.setSelectedIndex(getListIndex(readFollowup.getMEDICATIONCOMPLIANCE(), ywycx_list));
			adapter_ywblfy.setChecked(readFollowup.getADR());
			adapter_ywblfy.setChecked(adapter_ywblfy.getChecked(), readFollowup.getADR_EX());
			ed_zzyy.setText(readFollowup.getREFERRALREASON());
			ed_jgkb.setText(readFollowup.getREFERRALORG());

			if (!TextUtils.isEmpty(readFollowup.getRES4())) {
				Glide.with(getActivity()).load(readFollowup.getRES4()).into(iv_paizhao_img);
			}

			if (!TextUtils.isEmpty(readFollowup.getRes17())) {
				strPatientSignPath = readFollowup.getRes17();
				setSign(readFollowup.getRes17(), img_patientsign);
			}

			if (readFollowup.getNEXTFOLLOWUPDATE() != null) {
				try {
					ed_xcsfsj.setText(dateFormat.format(readFollowup.getNEXTFOLLOWUPDATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		} else {
			ed_date.setText(dateFormat.format(new Date()));
//			setDefaultFollowUpData();

			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfys.setSelectedIndex(i);
				}
			}
		}
		// drugCondition1.setTYPE("1");
		// if (!TextUtils.isEmpty(medicine1)) {
		// drugCondition1.setNAME(medicine1);
		// drugCondition1.setDAILYTIME(getInt(count1));
		// drugCondition1.setEVERYTIMEMG(getInt(dose1));
		// fdbmanger.save(drugCondition1);
		// }
		List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
				strWhere + "AND TYPE = '1' and PARENTID = '" + id + "'");
		sfDrugList = drugList;
		sfDrugAdapter.setNewData(sfDrugList);
		if (drugList.size() > 0) {
			fromCD_DR = 1;
			int size = drugList.size();
//			EditText[] medicals = { ed_ywmc1, ed_ywmc2, ed_ywmc3, ed_qtyw };
//			EditText[] doses = { ed_ywmc1_mg, ed_ywmc2_mg, ed_ywmc3_mg, ed_qtyw_mg };
//			EditText[] times = {nice_spinner_cc1,nice_spinner_cc2,nice_spinner_cc3,nice_spinner_cc4};
//			EditText[] times2 = {nice_spinner_yl1,nice_spinner_yl2,nice_spinner_yl3,nice_spinner_yl4};

//			for (int i = 0; i < size; i++) {
//				CD_DRUGCONDITION drug = drugList.get(i);
//				medicals[i].setText(notNull(drug.getNAME()));
//				if (i == 0) {
//					nice_spinner_dw1.setText(notNull(drug.getRES1()));
//					drugTime1.setText(notNull(drug.getRES2()));
//				} else if (i == 1) {
//					nice_spinner_dw2.setText(notNull(drug.getRES1()));
//					drugTime2.setText(notNull(drug.getRES2()));
//				} else if (i == 2) {
//					nice_spinner_dw3.setText(notNull(drug.getRES1()));
//					drugTime3.setText(notNull(drug.getRES2()));
//				} else if (i == 3) {
//					nice_spinner_dwqt.setText(notNull(drug.getRES1()));
//					drugTime4.setText(notNull(drug.getRES2()));
//				}
//				String dailytime = drug.getDAILYTIME();
//				if(null != dailytime && !dailytime.equals("")){
//					if(dailytime.contains("/")){
//						String[] split = dailytime.split("/");
//						if(null != split && !split.equals("")){
//							String s = split[1];
//							if(null != s && !s.equals("")){
//								times[i].setText(notNull(s));
//							}
//							String s1 = split[0];
//							if(null != s1 && !s1.equals("")){
//								times2[i].setText(notNull(s1));
//							}
//						}
//					}
//				}
////                times[i].setText(notNull(drug.getDAILYTIME()));
//				doses[i].setText(notNull(String.valueOf(drug.getEVERYTIMEMG())));
//
//			}
		}

		if (id == -1) {
			setHistoryDrugData();
		}
	}

	private void setDefaultFollowUpData() {

		try {
			List<CD_DIABETESFOLLOWUP> tnbItemOne = fdbmanger.findAllByWhere(CD_DIABETESFOLLOWUP.class,
					strWhere,"ID DESC LIMIT 1");
			if (tnbItemOne != null && tnbItemOne.size() > 0) {
                CD_DIABETESFOLLOWUP tnbFollowup = tnbItemOne.get(0);

				ed_date.setDate(tnbFollowup.getFOLLOWUP_DATE());
				for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
					if (NovaApplication.getDoctorList().get(i).getUSER_ID().equals(tnbFollowup.getFOLLOWUPDOCTOR())) {
						ed_sfys.setSelectedIndex(i);
					}
				}
				String symptoms = tnbFollowup.getSYMPTOM();
				adapter_zz.setChecked(symptoms);
				adapter_zz.setOther(tnbFollowup.getSYMPTOMOTHER());

				if (tnbFollowup.getFOLLOWUPWAY().contains("DM04-04")){
					nice_spinner_szfs.setSelectedIndex(getListIndex(tnbFollowup.getFOLLOWUPWAY().replace("DM04-04","DM04-15"), szfs_list));
				}else{
					nice_spinner_szfs.setSelectedIndex(getListIndex(tnbFollowup.getFOLLOWUPWAY(), szfs_list));
				}
				if (!TextUtils.isEmpty(tnbFollowup.getHYPERTENSION())) {
					if ((!TextUtils.isEmpty(tnbFollowup.getHYPERTENSION()))
							&& (!TextUtils.isEmpty(tnbFollowup.getHYPOTENSION()))) {
					}
					Log.e(TAG, "111setDBData: " + tnbFollowup.getHYPERTENSION() + "/" + tnbFollowup.getHYPOTENSION());
					ed_xy.setText(notNull(tnbFollowup.getHYPERTENSION() + "/" + tnbFollowup.getHYPOTENSION()));
				}else {

				}
				ed_tz.setText(notNull(tnbFollowup.getWEIGHT()));
				ed_xcsfmb_tz.setText(notNull(tnbFollowup.getWEIGHTTARGET()));
				ed_height.setText(notNull(tnbFollowup.getHeight()));
//				ed_tzzs.setText(GlobalConts.getFormattedBMI(notNull(tnbFollowup.getBMI())));
//				ed_tzzs_sf.setText(GlobalConts.getFormattedBMI(notNull(tnbFollowup.getBMITARGET())));
				ed_qt.setText(notNull(tnbFollowup.getPHYSICALSYMPTOMOTHER()));

				setBMI(ed_height, ed_tz, ed_tzzs);
				setBMI(ed_height, ed_tz, ed_tzzs_sf);

				if(!TextUtils.isEmpty(tnbFollowup.getISREFERRAL())){
					isREFERRAL = tnbFollowup.getISREFERRAL();
					if("DM01-11_1".equals(tnbFollowup.getISREFERRAL())){
						zhuanzhen_no.setChecked(true);
						zhuanzhen_yes.setChecked(false);
//						zhuanzhen_layout.setVisibility(View.GONE);
					}else if("DM01-11_2".equals(tnbFollowup.getISREFERRAL())){
						zhuanzhen_yes.setChecked(true);
						zhuanzhen_no.setChecked(false);
//						zhuanzhen_layout.setVisibility(View.VISIBLE);
					}
				}
				zhuanzhen_layout.setVisibility(View.VISIBLE);


				if(!TextUtils.isEmpty(tnbFollowup.getRes11())){
					shifoushifang = tnbFollowup.getRes11();
					if("DM01-10_1".equals(tnbFollowup.getRes11())){
						shifang_no.setChecked(true);
						shifang_yes.setChecked(false);
					}else if("DM01-10_2".equals(tnbFollowup.getRes11())){
						shifang_yes.setChecked(true);
						shifang_no.setChecked(false);
					}
				}
				if(!TextUtils.isEmpty(tnbFollowup.getRes13())){
					suifangleixing = tnbFollowup.getRes13();
					if("FOLLOW_UP_TYPE_1".equals(tnbFollowup.getRes13())){
						sflx_zc.setChecked(true);
						sflx_erci.setChecked(false);
					}else if("FOLLOW_UP_TYPE_2".equals(tnbFollowup.getRes13())){
						sflx_erci.setChecked(true);
						sflx_zc.setChecked(false);
					}
				}
				if(!TextUtils.isEmpty(tnbFollowup.getRes15())){
					zhuanzhenjieguo = tnbFollowup.getRes15();
					if("ROLLOUT_RESULT_TYPE_1".equals(tnbFollowup.getRes15())){
						jieguo_no.setChecked(true);
						jieguo_yes.setChecked(false);
					}else if("ROLLOUT_RESULT_TYPE_2".equals(tnbFollowup.getRes15())){
						jieguo_yes.setChecked(true);
						jieguo_no.setChecked(false);
					}
				}
				if(!TextUtils.isEmpty(tnbFollowup.getRes16())){
					nextguanli = tnbFollowup.getRes16();
					if("NEXT_M_M_1".equals(tnbFollowup.getRes16())){
						xybglcs1.setChecked(true);
						xybglcs2.setChecked(false);
						xybglcs3.setChecked(false);
						xybglcs4.setChecked(false);
					}else if("NEXT_M_M_2".equals(tnbFollowup.getRes16())){
						xybglcs1.setChecked(false);
						xybglcs2.setChecked(true);
						xybglcs3.setChecked(false);
						xybglcs4.setChecked(false);
					}else if("NEXT_M_M_3".equals(tnbFollowup.getRes16())){
						xybglcs1.setChecked(false);
						xybglcs2.setChecked(false);
						xybglcs3.setChecked(true);
						xybglcs4.setChecked(false);
					}else if("NEXT_M_M_4".equals(tnbFollowup.getRes16())){
						xybglcs1.setChecked(false);
						xybglcs2.setChecked(false);
						xybglcs3.setChecked(false);
						xybglcs4.setChecked(true);
					}
				}
				et_shifang.setText(notNull(tnbFollowup.getRes12()));
				ed_zzphone.setText(notNull(tnbFollowup.getRes14()));
				beizhu.setText(notNull(tnbFollowup.getRes18()));

				jiankangjianyi.setText(notNull(tnbFollowup.getHEALTH_ASSESS()));

				ed_rxyl.setText(notNull(tnbFollowup.getDAILYSMOKENUM()));
				ed_xcsfmb_xy.setText(notNull(tnbFollowup.getDAILYSMOKENUMTARGET()));
				ed_ryjl.setText(notNull(tnbFollowup.getDAILYDRINKNUM()));
				ed_xcsfmb_yj.setText(notNull(tnbFollowup.getDAILYDRINKNUMTARGET()));
//				syqk_edt.setText(notNull(tnbFollowup.getTOSALT()));
				ed_yd_zq.setText(notNull(tnbFollowup.getSPORTTIMEPERWEEK()));
				ed_yd_min.setText(notNull(tnbFollowup.getSPORTPERMINUTETIME()));
				ed_xcsfmb_yd_zq.setText(notNull(tnbFollowup.getSPORTTIMESPERWEEKTARGET()));
				ed_xcsfmb_yd_min.setText(notNull(tnbFollowup.getSPORTPERMINUTESTIMETARGET()));
				ed_fzjc.setText(tnbFollowup.getSubCheck());

//				nice_spinner_syqk.setSelectedIndex(getListIndex(tnbFollowup.getEATSALTTYPE(), sy_list));
//				nice_spinner_xcsfmb.setSelectedIndex(getListIndex(tnbFollowup.getEATSALTTARGET(), xcsfmb_list));
				nice_spinner_xltz.setSelectedIndex(getListIndex(tnbFollowup.getPSYCHOADJUSTMENT(), xltz_list));
				nice_spinner_zyxw.setSelectedIndex(getListIndex(tnbFollowup.getOBEYDOCTORBEHAVIOR(), zyxw_list));
				nice_spinner_clsffl.setSelectedIndex(getListIndex(tnbFollowup.getFOLLOWUPTYPE(), ccsffl_list));
				nice_spinner_fyycx.setSelectedIndex(getListIndex(tnbFollowup.getMEDICATIONCOMPLIANCE(), ywycx_list));
				adapter_ywblfy.setChecked(tnbFollowup.getADR());
				adapter_ywblfy.setChecked(adapter_ywblfy.getChecked(), tnbFollowup.getADR_EX());
				ed_zzyy.setText(tnbFollowup.getREFERRALREASON());
				ed_jgkb.setText(tnbFollowup.getREFERRALORG());

				if (!TextUtils.isEmpty(tnbFollowup.getRES4())) {
					Glide.with(getActivity()).load(tnbFollowup.getRES4()).into(iv_paizhao_img);
					mPhotoPath = tnbFollowup.getRES4();
				}
				if (!TextUtils.isEmpty(tnbFollowup.getRes17())) {
					strPatientSignPath = tnbFollowup.getRes17();
					setSign(tnbFollowup.getRes17(), img_patientsign);
				}

				if (tnbFollowup.getNEXTFOLLOWUP_DATE() != null) {
					try {
						ed_xcsfsj.setText(dateFormat.format(tnbFollowup.getNEXTFOLLOWUP_DATE()));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}


	protected String getThreeTime() {
		int mYear;
		int mMonth;
		int mDay;
		String fmt = null;
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH) + 4;

		String monStr = mMonth + "";
		if (monStr.length() == 1) {
			monStr = "0" + monStr;
		}

		mDay = c.get(Calendar.DAY_OF_MONTH);
		String dayStr = mDay + "";
		if (dayStr.length() == 1) {
			dayStr = "0" + dayStr;
		}

		fmt = "" + mYear + "-" + monStr + "-" + dayStr;
		return fmt;
	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		if (str != null && !str.equals("")) {

			for (int i = 0; i < bds.size(); i++) {
				if (str.equals(bds.get(i).getID())) {
					return i;
				}
			}
		}
		return 0;
	}

	private String notNull(String str) {
		if (TextUtils.isEmpty(str)) {
			return "";
		}
		return str;
	}

	public void save() {
		// 随诊方式
		String str_id = szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID();
		Log.w(TAG, "随诊方式：" + str_id);
		if (TextUtils.isEmpty(str_id)) {
			nice_spinner_szfs.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择随诊方式");
			return;
		} else {
			nice_spinner_szfs.setBackgroundColor(Color.WHITE);
		}

		// 症状
		String str_zz = adapter_zz.getCheckedIdsStr();
		if (TextUtils.isEmpty(str_zz)) {
			gd_zz.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择症状");
			return;
		} else {
			gd_zz.setBackgroundColor(Color.WHITE);
		}

		// 血压
		String str_xy = ed_xy.getText().toString();
		if (TextUtils.isEmpty(str_xy)) {
			ed_xy.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请填写血压");
			return;
		} else {
			if (!str_xy.contains("/")) {
				ed_xy.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("血压数据不合理，保存失败");
				return;
			} else {
				String[] split = str_xy.split("/");
				if (!GlobalConts.isRightNumber("血压", split[0])) {
					ed_xy.setBackgroundColor(Color.YELLOW);
					((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
					return;
				}else if (!GlobalConts.isRightNumber("血压", split[1])) {
					ed_xy.setBackgroundColor(Color.YELLOW);
					((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
					return;
				}else{
					int age = GlobalConts.getAge(userInfo.getBIRTHDAY());
//					if (age >= 65) {

					if (false) {
						int gy = Integer.parseInt(split[0]);
						int dy = Integer.parseInt(split[1]);
//						String checked = adapter_ywblfy.getChecked();
//						if ((gy > 149 || dy > 89) && checked.equals("DM01-11_1")) {
//							Toast.makeText(getActivity(),
//									"65岁及以上老年人血压不高于149/89情况下无药物不良反应，" +
//									"应可以选择控制满意",Toast.LENGTH_SHORT).show();
//							return;
//						}else {
//							gaoya = split[0];
//							diya = split[1];
//						}
					}else {
						gaoya = split[0];
						diya = split[1];
					}

				}
			}
			ed_xy.setBackgroundColor(Color.WHITE);
		}

		if(ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID().equals("DM01-71_1")){

			int aa = Integer.parseInt(gaoya);
			int bb = Integer.parseInt(diya);
			Log.e(TAG,"进来了："+aa+bb);
//			if(aa > 139){
//				((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
//				return;
//			}
//			if(bb > 89){
//				((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
//				return;
//			}
//			String checked = adapter_ywblfy.getChecked();
//			if(checked.equals("DM01-11_2")){
//				((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
//				return;
//			}
		}
		// 心率
		String str_xl = ed_xl.getText().toString();
		if (TextUtils.isEmpty(str_xl)) {
			ed_xl.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入心率");
			return;
		} else {
			ed_xl.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("脉率",str_xl )) {
				ed_xl.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("心率数据不合理，保存失败！");
				return;
			}
		}

		// 体重
		String str_tz = ed_tz.getText().toString();
		if (TextUtils.isEmpty(str_tz)) {
			ed_tz.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入体重");
			return;
		} else {
			ed_tz.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("体重",str_tz )) {
				ed_tz.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("体重数据不合理，保存失败！");
				return;
			}
			if(null != str_tz && !str_tz.equals("")){
				Double mweight =Double.valueOf(str_tz);
				if(mweight < 10 || mweight > 300){
					((GXYActivity) getActivity()).showTextDialog("体重数据不合理，保存失败！");
					return;
				}
			}
		}

		// 身高
		String str_height = ed_height.getText().toString();
		if (TextUtils.isEmpty(str_height)) {
			ed_height.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入身高");
			return;
		} else {
			ed_height.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("身高",str_height )) {
				ed_height.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("身高数据不合理，保存失败！");
				return;
			}
			if(null != str_height && !str_height.equals("")){
				Double mheight = Double.valueOf(str_height);
				if(mheight < 10 || mheight > 300){
					((GXYActivity) getActivity()).showTextDialog("身高数据不合理，保存失败！");
					return;
				}
			}
		}
		// 体质指数
		String str_tzzs = ed_tzzs.getText().toString();
		if (TextUtils.isEmpty(str_tzzs)) {
			ed_tzzs.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入体质指数");
			return;
		} else {

			if (!GlobalConts.isRightNumber("体质指数",str_tzzs )) {
				((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
				return;
			}

		}

		String ed_tzzs_sfStr = ed_tzzs_sf.getText().toString();
		if (!TextUtils.isEmpty(ed_tzzs_sfStr)) {
			if (!GlobalConts.isRightNumber("体质指数",ed_tzzs_sfStr )) {
				((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
				return;
			}
		}


		// 下次随访时间
		String str_xcsfsj = ed_xcsfsj.getText().toString();
		if (TextUtils.isEmpty(str_xcsfsj)) {
			ed_xcsfsj.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择下次随访时间");
			return;
		} else {
			ed_xcsfsj.setBackgroundColor(Color.WHITE);
		}

		followUp = new CD_HYPERTENSIONFOLLOWUP();
		saveBase();
		saveTizheng();
		saveLife();
//		saveMedicine();
		followUp.setIS_UPDATE("Y");
		followUp.setIS_UPDATE_NEW("Y");
		followUp.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		// List<CD_HYPERTENSIONFOLLOWUP> list =
		// fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, strWhere);
		// if (list.size() > 0) {
		// for (CD_HYPERTENSIONFOLLOWUP info : list) {
		// fdbmanger.delete(info);
		// }
		// }
//		String shifoushifang = "DM01-11_1";//是否失访
//		String suifangleixing = "FOLLOW_UP_TYPE_1";// 随访类型
//		String zhuanzhenjieguo = "ROLLOUT_RESULT_TYPE_1";// 随访类型
//		String nextguanli = "NEXT_M M 1’";// 下一步管理措施
		followUp.setRes11(shifoushifang);
		followUp.setRes13(suifangleixing);
		followUp.setRes15(zhuanzhenjieguo);
		followUp.setRes16(nextguanli);

		if (!TextUtils.isEmpty(ed_ywmc11.getText().toString().trim())) {
			followUp.setDrug11(notNull(ed_ywmc11.getText().toString().trim()));
			followUp.setDrug12(notNull(ed_ywmc12.getText().toString().trim()));
			followUp.setDrug13(notNull(ed_ywmc13.getText().toString().trim()));
			followUp.setDrug14(notNull(ed_ywmc14.getText().toString().trim()));
		}
		if (!TextUtils.isEmpty(ed_ywmc21.getText().toString().trim())) {
			followUp.setDrug21(notNull(ed_ywmc21.getText().toString().trim()));
			followUp.setDrug22(notNull(ed_ywmc22.getText().toString().trim()));
			followUp.setDrug23(notNull(ed_ywmc23.getText().toString().trim()));
			followUp.setDrug24(notNull(ed_ywmc24.getText().toString().trim()));
		}
		if (!TextUtils.isEmpty(ed_ywmc31.getText().toString().trim())) {
			followUp.setDrug31(notNull(ed_ywmc31.getText().toString().trim()));
			followUp.setDrug32(notNull(ed_ywmc32.getText().toString().trim()));
			followUp.setDrug33(notNull(ed_ywmc33.getText().toString().trim()));
			followUp.setDrug34(notNull(ed_ywmc34.getText().toString().trim()));
		}
		if (!TextUtils.isEmpty(ed_ywmc41.getText().toString().trim())) {
			followUp.setDrug41(notNull(ed_ywmc41.getText().toString().trim()));
			followUp.setDrug42(notNull(ed_ywmc42.getText().toString().trim()));
			followUp.setDrug43(notNull(ed_ywmc43.getText().toString().trim()));
			followUp.setDrug44(notNull(ed_ywmc44.getText().toString().trim()));
		}

		String shifangyuanyin = et_shifang.getText().toString().trim();
		if (!TextUtils.isEmpty(shifangyuanyin)) {
			followUp.setRes12(shifangyuanyin);
		}
		String ed_zzphonetext = ed_zzphone.getText().toString().trim();
		if (!TextUtils.isEmpty(ed_zzphonetext)) {
			followUp.setRes14(ed_zzphonetext);
		}
		String beizhutext = beizhu.getText().toString().trim();
		if (!TextUtils.isEmpty(beizhutext)) {
			followUp.setRes18(beizhutext);
		}

		followUp.setISREFERRAL(isREFERRAL);
		followUp.setREFERRALREASON(ed_zzyy.getText().toString());
		followUp.setREFERRALORG(ed_jgkb.getText().toString());
		if(!TextUtils.isEmpty(jiankangjianyi.getText())){
			followUp.setHEALTH_ASSESS(jiankangjianyi.getText().toString());
		}

		if (!TextUtils.isEmpty(str_xcsfsj)) {
			try {
				followUp.setNEXTFOLLOWUPDATE((Date) dateFormat.parse(str_xcsfsj));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		// 拍照
		// mPhotoPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/report/123456.png";
		if (!TextUtils.isEmpty(mPhotoPath)) {
			followUp.setRES4(mPhotoPath);
		}

		if (!TextUtils.isEmpty(strPatientSignPath)) {
			followUp.setRes17(strPatientSignPath);
		}
		//处理随访次数
		List<CD_HYPERTENSIONFOLLOWUP> list = NovaApplication.fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, " IDCARD='"+followUp.getIDCARD()+"'");


		followUp.setLAST_UPDATE_DATE(new Date());
		followUp.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
//		if (fromCD_HY == 1) {
		if (id != -1) {
			followUp.setUPDATEORG(NovaApplication.getJgbh());
			followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
			if(null!=list){
				followUp.setRES3(list.size()+"");
			}else{
				followUp.setRES3("1");
			}
			fdbmanger.updata(followUp, "IDCARD='" + userInfo.getIDCARD() + "' and id = '" + id + "'");
		} else {
			followUp.setCREATED_BY(userInfo.getCREATED_BY());
			followUp.setCREATED_DATE(new Date());
			followUp.setCREATEORG(NovaApplication.getJgbh());
			followUp.setCREATER(NovaApplication.getJgrno());
			if(null!=list){
				followUp.setRES3(list.size()+1+"");
			}else{
				followUp.setRES3("1");
			}
			fdbmanger.save(followUp);
			fromCD_HY = 1;

			List<CD_HYPERTENSIONFOLLOWUP> gyxItemOne = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class,
					strWhere,"ID DESC LIMIT 1");
			if (gyxItemOne != null && gyxItemOne.size() > 0) {
				id = gyxItemOne.get(0).getID();
				followUp.setID(id);
			}
		}
		saveMedicine();
		// ((GXYActivity) getActivity()).showTextDialog("保存成功");
		Log.e(TAG, "tt" + NovaApplication.getType());
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
//			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
//					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//
//						@Override
//						public void onClick(DialogInterface dialog, int which) {
//							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
//							intent.putExtra("type", "06");
//							intent.putExtra("szfs", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
//							startActivity(intent);
//						}
//					}).show();
			String populationType = userInfo.getPOPULATION_TYPE();
			if (!TextUtils.isEmpty(populationType) && populationType.contains("7")) {
				new AlertDialog.Builder(getActivity()).setTitle("随访保存成功，是否跳转糖尿病随访")
						.setPositiveButton("确定", new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								SfHistoryBean sfHistoryBean = new SfHistoryBean();
								sfHistoryBean.setFollowupDate(TimeUtils.date2String(followUp.getFOLLOWUPDATE(), "yyyy-MM-dd"));
								Intent intent = new Intent(getContext(), TNBActivity.class);
							    intent.putExtra("data", sfHistoryBean);
//							intent.putExtra("type", "07");
//							intent.putExtra("szfs", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
								startActivity(intent);
							}
						})
						.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {

							}
						})
						.show();
			} else {
				new AlertDialog.Builder(getActivity()).setTitle("保存成功")
						.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
					}
				}).show();
			}
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((GXYActivity) getActivity()).showTextDialog("保存成功");
		}
	}

	private void saveMedicine() {

		List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
				"IDCARD = '" + NovaApplication.getUserInfo().getIDCARD()
						+ "' and TYPE='1' and PARENTID = '" + id + "'");
		for (CD_DRUGCONDITION drug : drugList) {
			fdbmanger.delete(drug);
		}

		for (int i = 0; i < sfDrugList.size(); i++) {
			CD_DRUGCONDITION cdDrugcondition = sfDrugList.get(i);
			if (!TextUtils.isEmpty(cdDrugcondition.getNAME())) {
				/** 类型 1高血压 2糖尿病 3精神疾病 4冠心病 5脑卒中 */
				cdDrugcondition.setTYPE("1");
				cdDrugcondition.setPARENTID(id);
				cdDrugcondition.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
				fdbmanger.save(cdDrugcondition);
			}
		}
//		String medicine1 = ed_ywmc1.getText().toString();
//		String yl1 = nice_spinner_yl1.getText().toString();
//		String dw1 = nice_spinner_dw1.getText().toString();
//		String cc1 = nice_spinner_cc1.getText().toString();
//		String dose1 = ed_ywmc1_mg.getText().toString();
//
//		CD_DRUGCONDITION drugCondition1 = new CD_DRUGCONDITION();
//		CD_DRUGCONDITION drugCondition2 = new CD_DRUGCONDITION();
//		CD_DRUGCONDITION drugCondition3 = new CD_DRUGCONDITION();
//		CD_DRUGCONDITION drugCondition4 = new CD_DRUGCONDITION();
//		if (!TextUtils.isEmpty(medicine1)) {
//			drugCondition1.setNAME(medicine1);
//			drugCondition1.setDAILYTIME(yl1 + "/" + cc1);
//			drugCondition1.setRES3(yl1);
//			drugCondition1.setRES4(cc1);
//			drugCondition1.setEVERYTIMEMG(dose1);
//			drugCondition1.setRES1(dw1);
//			drugCondition1.setRES2(notNull(drugTime1.getText().toString().trim()));
//			fdbmanger.save(drugCondition1);
//		}

	}

	private void saveLife() {

		String fuzhuJiancha = ed_fzjc.getText().toString();

		followUp.setDAILYSMOKENUM(ed_rxyl.getText().toString());
		followUp.setDAILYDRINKNUM(ed_ryjl.getText().toString());
		followUp.setDAILYDRINKNUMTARGET(ed_xcsfmb_yj.getText().toString());
		if(!TextUtils.isEmpty(syqk_edt.getText())){
			followUp.setTOSALT(syqk_edt.getText().toString());
		}

		followUp.setDAILYSMOKENUMTARGET(ed_xcsfmb_xy.getText().toString());
		followUp.setSPORTTIMEPERWEEK(ed_yd_zq.getText().toString());
		followUp.setSPORTTIMESPERWEEKTARGET(ed_xcsfmb_yd_zq.getText().toString());
		followUp.setSPORTPERMINUTESTIMETARGET(ed_xcsfmb_yd_min.getText().toString());
		followUp.setSPORTPERMINUTETIME(ed_yd_min.getText().toString());
		followUp.setASSISTANTEXAM(fuzhuJiancha);
		followUp.setEATSALTTYPE(sy_list.get(nice_spinner_syqk.getSelectedIndex()).getID());
		followUp.setEATSALTTARGET(xcsfmb_list.get(nice_spinner_xcsfmb.getSelectedIndex()).getID());
		followUp.setPSYCHOADJUSTMENT(xltz_list.get(nice_spinner_xltz.getSelectedIndex()).getID());
		followUp.setOBEYDOCTORBEHAVIOR(zyxw_list.get(nice_spinner_zyxw.getSelectedIndex()).getID());
		followUp.setMEDICATIONCOMPLIANCE(ywycx_list.get(nice_spinner_fyycx.getSelectedIndex()).getID());
		Log.e("随诊方式---此次随访分了-------", ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());
		followUp.setFOLLOWUPTYPE(ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());
		String checked = adapter_ywblfy.getChecked();
		followUp.setADR(checked);
		followUp.setADR_EX(adapter_ywblfy.getCheckedOther());

	}

	private void saveTizheng() {
		String et_other = ed_qt.getText().toString();
		String str_xy = ed_xy.getText().toString();
		if (!TextUtils.isEmpty(str_xy)) {
			if (str_xy.contains("/")) {
				if (str_xy.split("/").length == 2) {
					followUp.setHYPERTENSION(str_xy.split("/")[0]);// 收缩压
					followUp.setHYPOTENSION(str_xy.split("/")[1]);// 舒张压
				} else {
					followUp.setHYPERTENSION("");// 收缩压
					followUp.setHYPOTENSION("");// 舒张压
				}
			} else {
				followUp.setHYPERTENSION("");// 收缩压
				followUp.setHYPOTENSION("");// 舒张压
			}
		} else {
			followUp.setHYPERTENSION("");// 收缩压
			followUp.setHYPOTENSION("");// 舒张压
		}
		// followUp.setHYPERTENSION(120);
		// followUp.setHYPOTENSION(80);
		followUp.setWEIGHT(ed_tz.getText().toString());
		followUp.setHeight(ed_height.getText().toString());
		followUp.setBMI(ed_tzzs.getText().toString());
		followUp.setHEARTRATE(ed_xl.getText().toString());
		followUp.setWEIGHTTARGET(ed_xcsfmb_tz.getText().toString());
		followUp.setBMITARGET(ed_tzzs_sf.getText().toString());
		followUp.setPHYSICALSYMPTOMOTHER(et_other);
	}

	private void saveBase() {

		try {
			String edDate = ed_date.getText().toString();
			Log.e("随访时间",edDate+"***********");
			followUp.setFOLLOWUPDATE(dateFormat.parse(edDate));
		}catch (Exception e){

		}
		followUp.setSYMPTOM(adapter_zz.getCheckedIdsStr());
		followUp.setSYMPTOMOTHER(adapter_zz.getOther());
		Log.e("tag", adapter_zz.getOther());
		followUp.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
		Log.e("随诊方式----------", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
		if (szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID().contains("DM04-04")){
			followUp.setFOLLOWUPWAY(szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID().replace("DM04-04","DM04-15"));
		}else{
			followUp.setFOLLOWUPWAY(szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
		}
		followUp.setUPDATEORG(NovaApplication.getJgbh());
		followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
	}

	@Override
	public void onClick(View v) {

		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_choose_xy) {
			intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
		} else if (id == R.id.btn_choose_tz) {
			intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
		} else if (id == R.id.btn_choose_xl) {
			intent.putExtra("flag", "心率");
			getActivity().startActivityForResult(intent, GlobalConts.RequestMaiLv);
		} else if (id == R.id.bt_paizhao){
//			paizhao();
			startActivityForResult(new Intent(getActivity(), CameraActivity.class), REQUEST_CODE_PHOTO);
		}
	}

	@Override
	public void setXueya(String gaoya, String diya, String mailv) {
		if (!TextUtils.isEmpty(gaoya) && !TextUtils.isEmpty(diya)) {
			ed_xy.setText(gaoya + "/" + diya);
		}

	}

	@Override
	public void setTizhong(String value) {
		ed_tz.setText(value);

	}
	@Override
	public void setMaiLv(String mailv) {
		ed_xl.setText(mailv);
	}

	@Override
	public void updateSfData(int id) {

	}


	private final int REQUEST_CODE_PHOTO = 0x1005;
	private final int REQUEST_CODE_PHOTO1 = 0x1006;
	private final int REQUEST_CODE_PHOTOqianming = 0x1007;
	private String mPhotoPath;
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
	public void paizhao() {
		mPhotoPath = getPhotoPath();
		File mCurrentPhotoFile = new File(mPhotoPath);
		Intent intentC = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		if (Build.VERSION.SDK_INT >= 24) {
			Uri imageUri = FileProvider.getUriForFile(getActivity(),
					"com.health" + ".fileprovider", mCurrentPhotoFile);
			intentC.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
			intentC.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
		} else {
			intentC.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCurrentPhotoFile));
		}
		startActivityForResult(intentC, REQUEST_CODE_PHOTO);
	}

	private String getPhotoPath() {
		String str = "";
		File file = new File(Environment.getExternalStorageDirectory() + "/PublicHealth/images/");
		str = Environment.getExternalStorageDirectory() + "/PublicHealth/images/" + userInfo.getIDCARD() + "_"
				+  "_" + sdf.format(new Date()) + "_"
				+ (int) ((Math.random() * 9 + 1) * 1000) + ".png";
		if (!file.exists()) {
			file.mkdirs();
		}
		return str;
	}

	private void setHistoryDrugData() {
		try {
			List<CD_HYPERTENSIONFOLLOWUP> list = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class,
					strWhere, "ID DESC");
			if (list != null && list.size() > 0) {
				List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
						"IDCARD = '" + NovaApplication.getUserInfo().getIDCARD()
								+ "' and TYPE='1' and PARENTID = '" + list.get(0).getID() + "'");

				sfDrugList = drugList;
				sfDrugAdapter.setNewData(sfDrugList);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
